package com.ruoyi.web.controller.construction.supertube;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.supe.PlatformCoupon;
import com.ruoyi.system.service.zhaungxiuservice.shopService.PlatformCouponService;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平台优惠卷Controller
 *
 * @author ruoyi
 * @date 2020-12-18
 */
@RestController
@RequestMapping("/super/coupon")
public class PlatformCouponController extends BaseController {

    @Autowired
    private PlatformCouponService platformCouponService;


    @PreAuthorize("@ss.hasPermi('super:coupon:findAllList')")
    @GetMapping("/findAllList")
    public List<PlatformCoupon> findAllList(){
        return platformCouponService.findAllList();
    }



    /**
     * 查询平台优惠卷列表
     */
    @PreAuthorize("@ss.hasPermi('super:coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlatformCoupon platformCoupon)
    {
        startPage();
        List<PlatformCoupon> list = platformCouponService.selectPlatformCouponList(platformCoupon);
        return getDataTable(list);
    }


    /**
     * 导出平台优惠卷列表
     */
    @PreAuthorize("@ss.hasPermi('super:coupon:export')")
    @Log(title = "平台优惠卷", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PlatformCoupon platformCoupon)
    {
        List<PlatformCoupon> list = platformCouponService.selectPlatformCouponList(platformCoupon);
        ExcelUtil<PlatformCoupon> util = new ExcelUtil<PlatformCoupon>(PlatformCoupon.class);
        return util.exportExcel(list, "coupon");
    }

    /**
     * 获取平台优惠卷详细信息
     */
    @PreAuthorize("@ss.hasPermi('super:coupon:query')")
    @GetMapping(value = "/{platformId}")
    public AjaxResult getInfo(@PathVariable("platformId") Integer platformId)
    {
        return AjaxResult.success(platformCouponService.selectPlatformCouponById(platformId));
    }

    /**
     * 新增平台优惠卷
     */
    @PreAuthorize("@ss.hasPermi('super:coupon:add')")
    @Log(title = "平台优惠卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlatformCoupon platformCoupon)
    {
        return toAjax(platformCouponService.insertPlatformCoupon(platformCoupon));
    }

    /**
     * 修改平台优惠卷
     */
    @PreAuthorize("@ss.hasPermi('super:coupon:edit')")
    @Log(title = "平台优惠卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlatformCoupon platformCoupon)
    {
        return toAjax(platformCouponService.updatePlatformCoupon(platformCoupon));
    }

    /**
     * 删除平台优惠卷
     */
    @PreAuthorize("@ss.hasPermi('super:coupon:remove')")
    @Log(title = "平台优惠卷", businessType = BusinessType.DELETE)
    @DeleteMapping("/{platformIds}")
    public AjaxResult remove(@PathVariable Integer[] platformIds)
    {
        return toAjax(platformCouponService.deletePlatformCouponByIds(platformIds));
    }

    @GetMapping(value = "/findAllSum")
    public int findAllSum(){
        int allSum = platformCouponService.findAllSum();
        return allSum;
    }



}
